package com.mall.service;

import com.mall.mapper.layoutHeaderMapper;
import com.mall.pojo.goods;
import com.mall.pojo.layoutheader;
import com.mall.pojo.subCate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class layoutHeaderService {
    @Autowired
    private layoutHeaderMapper layoutHeaderMapper;
    @Autowired
    private subCateService subCateService;
    //查询所有主类别，同时给每个类别的goods,subcate赋值
    public List<layoutheader> findAll() {
       List<layoutheader>tables=layoutHeaderMapper.findAll();
       for(layoutheader table:tables){  //set good
           table.setGood(layoutHeaderMapper.findGoodsById(table.getId()));
           table.setSubCate(subCateService.findByParentId(table.getId()));
       }
       return tables;
    }
    //查询给定id的主类别
    public layoutheader findById(int id) {
        layoutheader table=layoutHeaderMapper.findById(id);
        table.setGood(layoutHeaderMapper.findGoodsById(id));
        table.setSubCate(subCateService.findByParentId(table.getId()));
        return table;
    }
}
